import * as express from 'express'
import Collection from '../models/Collection'

const router = express.Router()

router.post('/', (req, res, next) => {
  const { type, content } = req.body
  Collection.add({
    type,
    content,
  })
    .then(collection => res.json(collection))
    .catch(next)
})

router.delete('/', (req, res, next) => {
  Collection.delete({ id: req.query.id })
    .then(() => res.json({ done: 1 }))
    .catch(next)
})

router.get('/', (req, res, next) => {
  Collection.get({ id: req.query.id })
    .then(collection => res.json(collection))
    .catch(next)
})

export default router
